package com.loan.controller;


import com.loan.entity.Rate;
import com.loan.entity.Result;
import com.loan.mapper.RateMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author
 * @since 2024-10-02
 */
@RestController
@RequestMapping("/rate")
public class RateController {

    @Autowired
    RateMapper rateMapper;

    @RequestMapping(value = "/getRateList",method = RequestMethod.POST)
    public List<Rate> getRateList(){
        List<Rate> rateList = rateMapper.selectList(null);
        return rateList;
    }

    @RequestMapping(value = "/updateRate",method = RequestMethod.POST)
    public Result updateRate(Rate rate){

        /*Date date = new Date();
        String str = "yyy-MM-dd HH:mm:ss";
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat(str);
        String df = simpleDateFormat.format(date);*/

        rate.setDateTime(new Date());

        if (rate.getBankRateId()==null){
            rateMapper.insert(rate);
        }
        if (rate.getBankRateId()!=null){
            rateMapper.updateById(rate);
        }

        Result result = new Result();
        result.setSuccess(true);
        return result;
    }
    @RequestMapping(value = "/deleteRate",method = RequestMethod.POST)
    public Result deleteRate(@Param("bankRateId") Integer bankRateId){
        System.out.println(bankRateId);
        rateMapper.deleteById(bankRateId);
        Result result = new Result();
        result.setSuccess(true);
        return result;
    }

}

